package au.edu.utas.yu_qiao_group.luckyman.utils;

import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView;

import java.io.File;

import androidx.databinding.BindingAdapter;

public class ImageHelper {
  @BindingAdapter({"imageUrl", "fallbackSrc"})
  public static void setImageUrl(ImageView view, String filename, int fallbackSrc) {
    if (TextUtils.isEmpty(filename) == false) {
      view.setImageURI(Uri.fromFile(new File(view.getContext().getExternalFilesDir("my_capture"), filename)));
    } else {
      view.setImageResource(fallbackSrc);
    }
  }
}
